from flask import Blueprint,request

user_agent_bp = Blueprint(
    'user_agent_bp',
    __name__,
    url_prefix= '/ua'
    )

@user_agent_bp.before_request
def has_user_agent():
    print('has_user_agent')
    ua = request.headers.get('User-Agent')
    if not ua or ua == 'python-requests/2.23.0':
        return '检测到爬虫'
    else:
        print(ua)


@user_agent_bp.route('/')
def index():
    return '待爬取内容'